import pandas as pd
from matplotlib import pyplot as plt

plt.rcParams['figure.figsize'] = (8.0, 5.0)  # 固定显示大小
plt.rcParams['font.family'] = ['sans-serif']  # 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 设置中文字体
plt.rcParams['axes.unicode_minus'] = False  # 显示负号

# 原网址
# df = pd.read_html(io="https://www.creprice.cn/rank/cityforsale.html")[0]
# df.to_csv("./data/全国城市房价排行.csv",index=False)
# print(df)

df = pd.read_csv("./data/全国城市房价排行.csv")
print(df)

# 计算各城市平均房价
df1 = df.groupby("所属地级市")["单价（元/㎡）"].mean().sort_values(ascending=True)
print(df1)
